# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Dmytro Meleshko <qzlgeb.zryrfuxb@tznvy.pbz(rot13)>

pkgname=eslint-language-server
pkgver=2.4.0
pkgrel=1
pkgdesc='Language server for ESLint'
arch=('any')
url=https://github.com/Microsoft/vscode-eslint
license=('MIT')
depends=('nodejs')
makedepends=('npm')
conflicts=("vscode-$pkgname")
replaces=("vscode-$pkgname")
source=("${url}/archive/release/$pkgver/vscode-eslint-$pkgver.tar.gz")
b2sums=('2ed76020de4d05a0935e2adb6b44dd841685d5f273bacee43beae5f2decaecc6b5ef49caab9bbd6dfc9fb3c84dbcead3ffedf1005abd9091c6d542c681f0c39c')

prepare() {
  cd vscode-eslint-release-$pkgver
  npm ci
}

build() {
  cd vscode-eslint-release-$pkgver
  npm run compile:server
}

package() {
  install -d "$pkgdir"/usr/{bin,lib/node_modules/$pkgname}
  printf '%s\n' '#!/usr/bin/env node' "require('/usr/lib/node_modules/$pkgname/out/eslintServer.js');" >"$pkgdir"/usr/bin/$pkgname
  chmod +x "$pkgdir"/usr/bin/$pkgname
  ln -s $pkgname "$pkgdir"/usr/bin/vscode-$pkgname

  cd vscode-eslint-release-$pkgver
  install -Dm644 -t "$pkgdir"/usr/share/doc/$pkgname README.md
  install -Dm644 -t "$pkgdir"/usr/share/licenses/$pkgname License.txt

  cd server
  cp -r node_modules out package.json "$pkgdir"/usr/lib/node_modules/$pkgname
}
